{% extends "layouts/base.html" %}
{% load book_extras %}

{% block title %} Borrow Records {% endblock %} }
{% block stylesheets %}{% endblock stylesheets %}

{% block content %}

<div class="pcoded-content">
    <div class="pcoded-inner-content">
        <div class="page-header">
            <div class="page-block">
                <div class="row align-items-center">
                    <div class="col-md-12">
                        <div class="page-header-title">
                            <h5 class="m-b-10">所有借阅记录</h5>
                        </div>

                    </div>
                </div>
            </div>

        </div>

        <br>
        <div class="main-body">
            <div class="page-wrapper">
                <div class="row">
                    <div class="col-xl-12">
                        <div class="card">
                            <div class="card-header">
                                <h5>总共 {{count_total}} 种记录</h5>
                            </div>
                            {% show_messages %}


                            <div class="card-block ">
                                <div class='row'>
                                    <div class="col-8">
                                        <b>排序方式： </b>
                                        <a href="{% url 'record_list' %}?search={{search}}&orderby=id">编号</a>  |
                                        <a href="{% url 'record_list' %}?search={{ search }}&orderby=borrower">姓名</a> |
                                        <a href="{% url 'record_list' %}?search={{ search }}&orderby=book">书籍</a> |
                                        <a href="{% url 'record_list' %}?search={{ search }}&orderby=start_day">借阅日期</a> |
                                        <a href="{% url 'record_list' %}?search={{ search }}&orderby=end_day">应归还日期</a>|
                                        <a href="{% url 'record_list' %}?search={{ search }}&orderby=closed_at">实际归还日期</a> |
                                        
                                    </div>
   
                                    <div class="col-auto">
                                        <form class="form-inline mb-2">
                                            <div class="form-group  mb-2">
                                                <input type="text" 
                                                       class="form-control" 
                                                       name="search",
                                                       id='search',
                                                       placeholder="name or card number",
                                                       value={{search}}
                                                       >
                                            </div>
                                            <button type="submit" class="btn btn-secondary mb-2 ml-1 btn-sm">搜索</button>
                                        </form>
                                    </div>
                                </div>

                                <div class="table-responsive table-hover">
                                    <table class="table">
                                        <thead>
                                            <tr>
                                                <th>姓名</th>
                                                <th>卡号</th>
                                                <th>电话号码</th>
                                                <th>书籍</th>
                                                <th>数量</th>
                                                <th>借阅日期</th>
                                                <th>归还日期</th>
                                                <th>状态</th>
                                                <th>延期归还</th>
                                                <th>###</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            
                                            {% for record in records %}
                                            <tr>
                                                <td>{{record.borrower}}</td>  
                                                <td>{{record.borrower_card}}</td>  
                                                <td>{{record.borrower_phone_number}}</td>
                                                <td>{{record.book|truncatewords:2}}</td>
                                                <td>{{record.quantity}}</td>
                                                <td>{{record.start_day|date:"Y-m-d"}}</td>
                                                <td>{{record.end_day|date:"Y-m-d"}}</td>
                                                <td>{{record.get_open_or_close_display}}</td>
                                                {% if record.return_status == "Delayed" %}
                                                <td class='table-danger'>{{record.return_status}} {{record.get_delay_number_days}} days</td>
                                                {% else %}
                                                <td class='table-success'>{{record.return_status}}</td>
                                                {% endif %}
                                                <td>
                                                    <a href="{% url 'record_detail' record.pk %}" class="badge badge-warning badge-bg"><i class="feather icon-eye"></i>&nbsp;查看</a>

                                                    <a href="{% url 'record_delete' record.pk %}" class="badge badge-danger"><i class="feather icon-trash-2"></i>&nbsp;删除</a>
                                                </td>
                                                    
                                            </tr>
                                            {% endfor %}


                                        </tbody>
                                    </table>
                                </div>
                                <div class="row">
                                    <div class='col-6'>
                                        <a href="{% url 'record_create' %}" class='btn btn-primary'>添加新的记录</a>
                                    </div>
                                    <div class='col-6'>
      
                                        {% show_pagination %}
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                </div>
            </div>
        </div>
    </div>
</div>

{% endblock content %}

{% block javascripts %}{% endblock javascripts %}
